package callnumber.gtdev5.com.photoVault.receiver;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

/**
 * Created by cheng
 * PackageName APP_Lock
 * 2018/1/15 16:31
 *          接收开机广播自动开启服务
 */

public class BootBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent mintent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(mintent.getAction())) {
            Intent intent = new Intent(context, AlarmReceiver.class);
            intent.setAction("arui.alarm.action");
            PendingIntent sender = PendingIntent.getBroadcast(context, 0,
                    intent, 0);
            long firstime = SystemClock.elapsedRealtime();
            AlarmManager am = (AlarmManager) context
                    .getSystemService( Context.ALARM_SERVICE);

            am.setRepeating( AlarmManager.ELAPSED_REALTIME_WAKEUP, firstime,
                    10 * 1000, sender);
        }
    }
}
